package com.cnhis.cloudhealth.clinical.clidoctor.cliparamter.bo;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;

import org.apache.zookeeper.ZooDefs.Ids;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cnhis.cloudhealth.clinical.clidoctor.cliparamter.dao.CliParamterDao;
import com.cnhis.cloudhealth.clinical.clidoctor.patientsearch.dao.PatientSearchDao;
import com.cnhis.cloudhealth.commons.Mappers.ModelVo;
import com.cnhis.cloudhealth.commons.newid.GetNewId;
import com.cnhis.cloudhealth.commons.utils.DateUtils;
import com.cnhis.cloudhealth.commons.utils.JsonUtil;
import java.util.HashMap;
import com.cnhis.cloudhealth.commons.utils.Page;
import com.cnhis.cloudhealth.commons.utils.StaticKeys;

import net.sf.json.JSONObject;

@SuppressWarnings("rawtypes")
@Service
public class CliParamterBo
{
    @Resource
    private CliParamterDao cliParamterDao;
    
    @Autowired
    private GetNewId getNewId;
    
    @Resource
    private PatientSearchDao patientSearchDao;
    
    public String getSysValue(Map map)
        throws Exception
    {
        return cliParamterDao.getSysParamValue(map);
    }
    
    public ModelVo queryAllPublicParamter(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        List list = null;
        try
        {
            list = cliParamterDao.queryAllPublicParamter(map);
            
        }
        catch (Exception e)
        {
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        mo.setList(list);
        mo.setRows(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        return mo;
    }
    
    public ModelVo operationScope()
        throws Exception
    {
        ModelVo mo = new ModelVo();
        List list = null;
        try
        {
            list = cliParamterDao.operationScope();
            
        }
        catch (Exception e)
        {
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        mo.setList(list);
        mo.setRows(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        return mo;
    }
    
    public ModelVo chargeStandards()
        throws Exception
    {
        ModelVo mo = new ModelVo();
        List list = null;
        try
        {
            list = cliParamterDao.chargeStandards();
            
        }
        catch (Exception e)
        {
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        mo.setList(list);
        mo.setRows(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        return mo;
    }
    
    public ModelVo prescriptionRestrictedCondition(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        List list = null;
        try
        {
            list = cliParamterDao.prescriptionRestrictedCondition(map);
            
        }
        catch (Exception e)
        {
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        mo.setList(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setRows(list);
        return mo;
    }
    
    @SuppressWarnings("unchecked")
    public ModelVo checkCrisisValue(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        List list = null;
        try
        {
            
            String value = cliParamterDao.getSysParamValue(map);
            map.put("para366", value == null || "".equals(value) ? 0 : Integer.parseInt(value));
            list = cliParamterDao.checkCrisisValue(map);
            
        }
        catch (Exception e)
        {
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        mo.setList(list);
        mo.setRows(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        return mo;
    }
    
    public ModelVo clinicalUnsupportHealthInsurance(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        List list = null;
        try
        {
            list = cliParamterDao.clinicalUnsupportHealthInsurance(map);
            
        }
        catch (Exception e)
        {
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        mo.setList(list);
        mo.setRows(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        return mo;
    }
    
    @SuppressWarnings("unchecked")
    public ModelVo checkIllnessMenu(Map map, int currPage, int pageSize)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        Page pg = null;
        try
        {
            String value = cliParamterDao.getSysParamValue(map);
            map.put("apara271", value);
            pg = cliParamterDao.checkIllnessMenu(map, currPage, pageSize);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        
        mo.setList(pg.getList());
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setTotal(pg.getTotalNumber());
        mo.setRows(pg.getList());
        return mo;
    }
    
    public ModelVo cliHomePagePatientBasicInfo(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        List list = null;
        try
        {
            list = cliParamterDao.cliHomePagePatientBasicInfo(map);
            
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        mo.setList(list);
        mo.setRows(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        return mo;
    }
    
    public ModelVo cliHomePageAllergy(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        List list = null;
        try
        {
            list = cliParamterDao.cliHomePageAllergy(map);
            
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        mo.setList(list);
        mo.setRows(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        return mo;
    }
    
    public ModelVo cliHomePageTreatmentRecord(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        List list = null;
        try
        {
            list = cliParamterDao.cliHomePageTreatmentRecord(map);
            
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        mo.setList(list);
        mo.setRows(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        return mo;
    }
    
    public ModelVo deleteTreatmentRecord(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        try
        {
            cliParamterDao.deleteTreatmentRecord(map);
            
        }
        catch (Exception e)
        {
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        
        mo.setResult(StaticKeys.OH_SUCCESS);
        return mo;
    }
    
    @SuppressWarnings({"unchecked"})
    public ModelVo execCliHomePageSaveInfo(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        try
        {
            String lxml = map.get("lXml").toString();
            JSONObject json = JSONObject.fromObject(lxml);
            
            JSONObject operInfo = json.getJSONObject("OperInfo");
            Map operInfoMap = JsonUtil.parserToMap(operInfo);
            JSONObject VAC1 = json.getJSONObject("VAC1");
            Map VAC1Map = JsonUtil.parserToMap(VAC1);
            List VAL1List = JsonUtil.parserToList(json.getJSONArray("VAL1"));
            List VAO1List = JsonUtil.parserToList(json.getJSONArray("VAO1"));
            map.put("operInfoMap", operInfoMap);
            map.put("VAC1Map", VAC1Map);
            map.put("VAL1List", VAL1List);
            map.put("VAO1List", VAO1List);
            // 病人年龄
            String ageN = getAgen(map);
            
            int VAA10 = Integer.parseInt(ageN.substring(0, ageN.length() - 1));
            String AAU01 = ageN.substring(ageN.length() - 1);
            
            String para58 = getPara58();
            int count = getTmpVACmAndPara58(map);
            if ((count > 0) && !"1".equals(para58))
            {
                map.put("lDate", DateUtils.getDateString(new Date()));
                if ("Y".equals(AAU01))
                {
                    map.put("domain", "YEAR");
                    
                }
                else if ("M".equals(AAU01))
                {
                    map.put("domain", "MONTH");
                }
                else if ("D".equals(AAU01))
                {
                    map.put("domain", "DAY");
                }
                else if ("H".equals(AAU01))
                {
                    map.put("domain", "HOUR");
                }
                else if ("N".equals(AAU01))
                {
                    map.put("domain", "MINUTE");
                }
                else if ("W".equals(AAU01))
                {
                    map.put("domain", "WEEK");
                }
                VAA10 = Integer.parseInt(getUAA10(map));
                
            }
            // 病人资料变更记录
            saveZAE1(map);
            map.put("VAA10", VAA10);
            map.put("AAU01", AAU01);
            // 变更病人资料和挂号记录
            updateVAA1AndVAC1(map);
            // 病人挂号附表 如果存在病人记录 @修改记录 @没有新增
            insertOrUpdateVCJ1(map);
            // 入院病人 修改 否新增
            insertOrUpdateVBN1(map);
            // 新增过敏记录
            insertVAL1(map);
            // 新增或修改诊断记录
            inertOrUpdateVAO1(map);
            // 新增资料修改历史记录
            insertZIU1(map);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        mo.setResult(StaticKeys.OH_SUCCESS);
        return mo;
    }
    
    @SuppressWarnings("unchecked")
    public void insertZIU1(Map map)
        throws Exception
    {
        map.put("ziu01", UUID.randomUUID());
        cliParamterDao.insertZIU1(map);
    }
    
    private void insertOrUpdateVCJ1(Map map)
        throws Exception
    {
        int count = cliParamterDao.VCJ1Param(map);
        if (count > 0)
        {
            cliParamterDao.updateVCJ1(map);
        }
        else
        {
            cliParamterDao.insertVCJ1(map);
        }
    }
    
    private void insertOrUpdateVBN1(Map map)
        throws Exception
    {
        int count = cliParamterDao.VBN1Param(map);
        if (count > 0)
        {
            count = cliParamterDao.VBN1Param1(map);
            if (count > 0)
            {
                cliParamterDao.updateVBN1(map);
            }
            else
            {
                cliParamterDao.insertVBN1(map);
            }
        }
    }
    
    @SuppressWarnings("unchecked")
    private void insertVAL1(Map map)
        throws Exception
    {
        int count = cliParamterDao.param1(map);
        if (count > 0)
        {
            Long newID = getNewId.nextId();
            map.put("val01", newID);
            cliParamterDao.insertVAL1(map);
        }
    }
    
    @SuppressWarnings({"unchecked"})
    private void inertOrUpdateVAO1(Map map)
        throws Exception
    {
        int count = cliParamterDao.tmpVAOmParam1(map);
        if (count > 0)
        {
            cliParamterDao.deleteVAO1(map);
            cliParamterDao.updateVAO1(map);
            count = cliParamterDao.tmpVAOmParam2(map);
            if (count > 0)
            {
                cliParamterDao.deleteVao1(map);
            }
            count = cliParamterDao.tmpVAOmParam3(map);
            if (count > 0)
            {
                map.put("aVAO01", getNewId.nextId());
                cliParamterDao.insertVao1(map);
            }
        }
    }
    
    public void updateVAA1AndVAC1(Map map)
        throws Exception
    {
        cliParamterDao.updateVAA1AndVAC1(map);
    }
    
    @SuppressWarnings("unchecked")
    private void saveZAE1(Map map)
        throws Exception
    {
        map.put("lZAE01", getNewId.nextId());
        int count = cliParamterDao.ZAE1param1(map);
        if (count > 0)
        {
            cliParamterDao.saveZAE1param1(map);
        }
        count = cliParamterDao.ZAE1param2(map);
        if (count > 0)
        {
            cliParamterDao.saveZAE1param2(map);
        }
    }
    
    @SuppressWarnings({"unchecked"})
    private String getPara58()
        throws Exception
    {
        HashMap hs = new HashMap();
        hs.put("productId", 9999);
        hs.put("programId", 9999);
        hs.put("paramNo", 58);
        String str = cliParamterDao.getSysParamValue(hs);
        return str == null ? "0" : str;
    }
    
    private String getAgen(Map map)
        throws Exception
    {
        String str = cliParamterDao.getAgen(map);
        return str == null ? "0" : str;
    }
    
    private int getTmpVACmAndPara58(Map map)
        throws Exception
    {
        return cliParamterDao.getTmpVACmAndPara58(map);
    }
    
    private String getUAA10(Map map)
        throws Exception
    {
        return cliParamterDao.setVAA10(map);
    }
    
    public ModelVo interfaceSetting()
        throws Exception
    {
        ModelVo mo = new ModelVo();
        List list = null;
        try
        {
            list = cliParamterDao.interfaceSetting();
            
        }
        catch (Exception e)
        {
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        mo.setList(list);
        mo.setRows(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        return mo;
    }
    
    public ModelVo patientLimit(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        List list = null;
        try
        {
            list = cliParamterDao.patientLimit(map);
            
        }
        catch (Exception e)
        {
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        mo.setList(list);
        mo.setRows(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        return mo;
    }
    
    @SuppressWarnings("unchecked")
    public ModelVo patientInfoPrint(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        Map m = null;
        try
        {
            m = cliParamterDao.patientInfoPrint(map);
            
        }
        catch (Exception e)
        {
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setMap(m);
        return mo;
    }
    
    public ModelVo admittedHospital(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        List list = null;
        try
        {
            list = cliParamterDao.admittedHospital(map);
            
        }
        catch (Exception e)
        {
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        mo.setList(list);
        mo.setRows(list);
        mo.setResult(StaticKeys.OH_SUCCESS);
        return mo;
    }
    
    public ModelVo deleteAdmittedHospital(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        try
        {
            cliParamterDao.deleteAdmittedHospital(map);
        }
        catch (Exception e)
        {
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        
        mo.setResult(StaticKeys.OH_SUCCESS);
        return mo;
    }
    
    private boolean systemParams(Map map)
        throws Exception
    {
        return cliParamterDao.systemtParams(map) == 0;
    }
    
    private boolean sysParamters(Map map)
        throws Exception
    {
        
        return cliParamterDao.sysParamters(map) > 0;
    }
    
    private void insertSysParams(Map map)
        throws Exception
    {
        
        cliParamterDao.insertSysParams(map);
    }
    
    private void deleteSYSUserParameters(Map map)
        throws Exception
    {
        cliParamterDao.deleteSYSUserParameters(map);
    }
    
    private void deleteUserParams(Map map)
        throws Exception
    {
        cliParamterDao.deleteUserParams(map);
    }
    
    @SuppressWarnings("unchecked")
    private Map getParamters(Map map)
        throws Exception
    {
        
        Map m = cliParamterDao.getParamters(map);
        map.put("EmpName", m.get("empname").toString());
        map.put("Host", m.get("host").toString());
        map.put("IP", m.get("ip").toString());
        m = cliParamterDao.getParamNameAndEvent(map);
        map.put("ProgramName", m.get("programname").toString());
        map.put("Event", m.get("event").toString());
        return map;
    }
    
    private void execSYSEventLogsInsert(Map map)
        throws Exception
    {
        cliParamterDao.execSYSEventLogsInsert(map);
    }
    
    private Long execCoreNewIdSYSEventLogs(Map map)
        throws Exception
    {
        return cliParamterDao.execCoreNewIdSYSEventLogs(map);
    }
    
    private void updateSysParams(Map map)
        throws Exception
    {
        cliParamterDao.updateSysParams(map);
    }
    
    private boolean queryParams(Map map)
        throws Exception
    {
        
        return cliParamterDao.queryParams(map) == 0;
    }
    
    @SuppressWarnings("unchecked")
    private void insertLogAndUpdateParams(Map map)
        throws Exception
    {
        map = getParamters(map);
        map.put("IncCount", 1);
        Long EventLogID = execCoreNewIdSYSEventLogs(map);
        map.put("EventLogID", EventLogID);
        map.put("MessageID", 0);
        // 新增系统时间日志
        execSYSEventLogsInsert(map);
        // 修改参数
        updateSysParams(map);
    }
    
    private void insertSystemUserParamters(Map map)
        throws Exception
    {
        if (queryParams(map))
        {
            updateSysParams(map);
        }
        cliParamterDao.insertSystemUserParamters(map);
    }
    
    @SuppressWarnings("unchecked")
    public ModelVo execSavedOneUserParameters(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo(StaticKeys.OH_SUCCESS);
        map.put("Pid", getNewId.nextId());
        map.put("Uid", getNewId.nextId());
        if (systemParams(map))
        {
            insertSysParams(map);
        }
        else
        {
            // 删除用户参数
            if (sysParamters(map) && "0".equals(map.get("Privilege").toString()))
            {
                deleteSYSUserParameters(map);
            }
            else
            {
                deleteUserParams(map);
            }
            if ("0".equals(map.get("Privilege").toString()))
            {
                if (Long.parseLong(map.get("UserID").toString()) > 0)
                {
                    // 增加日志 修改参数
                    insertLogAndUpdateParams(map);
                }
            }
            if ("1".equals(map.get("Privilege").toString()) || ("3".equals(map.get("Privilege").toString()))
                || ("2".equals(map.get("Privilege").toString())))
            {
                insertSystemUserParamters(map);
            }
        }
        return mo;
    }
    
    @SuppressWarnings("unchecked")
    public ModelVo execClinicBLP1Edit(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo(StaticKeys.OH_SUCCESS);
        String lxml = map.get("lxml").toString();
        List TmpBLPList = JsonUtil.getList(lxml);
        map.put("TmpBLPList", TmpBLPList);
        cliParamterDao.execClinicBLP1Edit(map);
        return mo;
    }
    
    private boolean BLP02(Map map)
        throws Exception
    {
        
        return cliParamterDao.BLP02(map) > 0;
    }
    
    private boolean BLP14(Map map)
        throws Exception
    {
        
        return cliParamterDao.BLP14(map) > 0;
    }
    
    private boolean BLP21(Map map)
        throws Exception
    {
        
        return cliParamterDao.BLP21(map) > 0;
    }
    
    private boolean BLP26(Map map)
        throws Exception
    {
        
        return cliParamterDao.BLP26(map) > 0;
    }
    
    private boolean BLP27(Map map)
        throws Exception
    {
        
        return cliParamterDao.BLP27(map) > 0;
    }
    
    private boolean BLP49(Map map)
        throws Exception
    {
        
        return cliParamterDao.BLP49(map) > 0;
    }
    
    private boolean BLP51(Map map)
        throws Exception
    {
        
        return cliParamterDao.BLP51(map) > 0;
    }
    
    // 修改限制条件参数验证
    @SuppressWarnings("unchecked")
    public ModelVo validationClinicBLP1EditParams(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo(StaticKeys.OH_SUCCESS);
        String lxml = map.get("lxml").toString();
        List TmpBLPList = JsonUtil.getList(lxml);
        map.put("TmpBLPList", TmpBLPList);
        if (TmpBLPList == null || TmpBLPList.size() == 0)
        {
            mo.setResult(StaticKeys.OH_FALSE);
            mo.setResultMsg("处方药品限制信息为空");
            return mo;
        }
        if (BLP02(map))
        {
            mo.setResult(StaticKeys.OH_FALSE);
            mo.setResultMsg("限制终止天数必须要大于等于零");
            return mo;
        }
        if (BLP14(map))
        {
            mo.setResult(StaticKeys.OH_FALSE);
            mo.setResultMsg("选项：医保病人限制开大额药品的医保险种判断，需要维护保险机构(类别id)及险种名称(项目id)");
            return mo;
        }
        if (BLP21(map))
        {
            mo.setResult(StaticKeys.OH_FALSE);
            mo.setResultMsg("选项：医保病人处方，限定同检查类型的诊疗项目一天内只允许开一次，需要维护检查类型(类别id)");
            return mo;
        }
        if (BLP26(map))
        {
            mo.setResult(StaticKeys.OH_FALSE);
            mo.setResultMsg("选项：对应类别下诊疗项目，门诊医保病人当天重复开时增加提示，需要维护诊疗类型(类别id)");
            return mo;
        }
        if (BLP27(map))
        {
            mo.setResult(StaticKeys.OH_FALSE);
            mo.setResultMsg("选项：默认提取最后一次医嘱时，需要剔除不提取的诊疗类别，需要维护诊疗类型(类别id)");
            return mo;
        }
        if (BLP49(map))
        {
            mo.setResult(StaticKeys.OH_FALSE);
            mo.setResultMsg("选项：限制诊疗类型项目下达医嘱数量不能输入零或不能输入小数，需要维护诊疗类型(类别id)");
            return mo;
        }
        if (BLP51(map))
        {
            mo.setResult(StaticKeys.OH_FALSE);
            mo.setResultMsg("选项：医保处方默认处方类型设置不对");
            return mo;
        }
        return mo;
    }
    
    public ModelVo execClinicBDP1edit(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo(StaticKeys.OH_SUCCESS);
        String lxml = map.get("lxml").toString();
        List TmpBDPList = JsonUtil.getList(lxml);
        if (TmpBDPList == null || TmpBDPList.size() == 0)
        {
            mo.setResult(StaticKeys.OH_FALSE);
            mo.setResultMsg("病人类别扩展信息为空");
            return mo;
        }
        cliParamterDao.execClinicBDP1edit(map);
        return mo;
    }
    
    public ModelVo sendAdviceHACRule()
        throws Exception
    {
        ModelVo mo = new ModelVo(StaticKeys.OH_SUCCESS);
        List ls = cliParamterDao.sendAdviceHACRule();
        mo.setList(ls);
        mo.setRows(ls);
        return mo;
    }
    
    public ModelVo limitDrug()
        throws Exception
    {
        ModelVo mo = new ModelVo(StaticKeys.OH_SUCCESS);
        List ls = cliParamterDao.sendAdviceHACRule();
        mo.setList(ls);
        mo.setRows(ls);
        return mo;
    }
    
    public ModelVo automaticMedicineOption()
        throws Exception
    {
        ModelVo mo = new ModelVo(StaticKeys.OH_SUCCESS);
        List ls = cliParamterDao.automaticMedicineOption();
        mo.setList(ls);
        mo.setRows(ls);
        return mo;
    }
    
    public ModelVo payTypeproperty()
        throws Exception
    {
        ModelVo mo = new ModelVo(StaticKeys.OH_SUCCESS);
        List ls = cliParamterDao.payTypeproperty();
        mo.setList(ls);
        mo.setRows(ls);
        return mo;
    }
    
    @SuppressWarnings("unchecked")
    public ModelVo pathLimitOption(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo(StaticKeys.OH_SUCCESS);
        Object aDate = map.get("aDate");
        if (aDate == null || "".equals(aDate.toString()))
        {
            map.put("aDate", DateUtils.getDateString(new Date()));
        }
        HashMap hs = new HashMap();
        hs.put("productId", 9999);
        hs.put("programId", 9999);
        hs.put("paramNo", 67);
        String para67 = cliParamterDao.getSysParamValue(hs);
        map.put("para67", para67);
        List ls = cliParamterDao.pathLimitOption(map);
        mo.setList(ls);
        mo.setRows(ls);
        return mo;
    }
    
    public ModelVo patientTypeExtends()
        throws Exception
    {
        ModelVo mo = new ModelVo(StaticKeys.OH_SUCCESS);
        List ls = cliParamterDao.patientTypeExtends();
        mo.setList(ls);
        mo.setRows(ls);
        return mo;
    }
    
    public ModelVo limitMedicalDays()
        throws Exception
    {
        ModelVo mo = new ModelVo(StaticKeys.OH_SUCCESS);
        List ls = cliParamterDao.limitMedicalDays();
        mo.setList(ls);
        mo.setRows(ls);
        return mo;
    }
    
    public ModelVo updateBDA1(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo(StaticKeys.OH_SUCCESS);
        try
        {
            
            cliParamterDao.updateBDA1(map);
        }
        catch (Exception e)
        {
            mo.setResult(StaticKeys.OH_FALSE);
        }
        return mo;
    }
    
    private String replaceSQL(Map map)
        throws Exception
    {
        return cliParamterDao.replaceSQL(map);
    }
    
    @SuppressWarnings("unchecked")
    public ModelVo execClinicAAS1Edit(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo(StaticKeys.OH_SUCCESS);
        try
        {
            String xml = replaceSQL(map);
            map.put("xml", xml);
            cliParamterDao.clinicAAS1Edit(map);
            
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
        }
        return mo;
    }
    
    public ModelVo guominList(Map map)
    {
        ModelVo mo = new ModelVo();
        try
        {
            List list = cliParamterDao.guominList(map);
            mo.setList(list);
            mo.setResult(StaticKeys.OH_SUCCESS);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
        }
        return mo;
    }

    public ModelVo jibingList(Map map)
    {
        ModelVo mo = new ModelVo();
        try
        {
            List list = cliParamterDao.jibingList(map);
            mo.setList(list);
            mo.setResult(StaticKeys.OH_SUCCESS);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
        }
        return mo;
    }

    public ModelVo yijuList(Map map)
    {
        ModelVo mo = new ModelVo();
        try
        {
            List list = cliParamterDao.yijuList(map);
            mo.setList(list);
            mo.setResult(StaticKeys.OH_SUCCESS);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
        }
        return mo;
    }

    public ModelVo zhenduanjieguoList(Map map)
    {
        ModelVo mo = new ModelVo();
        try
        {
            List list = cliParamterDao.zhenduanjieguoList(map);
            mo.setList(list);
            mo.setResult(StaticKeys.OH_SUCCESS);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
        }
        return mo;
    }

    public ModelVo saveVal1(Map map)
    {
        ModelVo mo = new ModelVo();
        try
        {
            List val1List = (List)map.get("val1List");
            List<Long> ids = new ArrayList<>();
            if (val1List!=null && !val1List.isEmpty())
            {
                ids = getNewId.nextId(val1List.size());
            }
            for(int i=0;i<val1List.size();i++)
            {
                Map<String, Object> temp = (Map<String, Object>)val1List.get(i);
                temp.put("val01", ids.get(i));
            }
            cliParamterDao.saveVal1(map);
            mo.setResult(StaticKeys.OH_SUCCESS);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
        }
        return mo;
    }

    public ModelVo queryGuominyaowu(Map map)
    {
        ModelVo mo = new ModelVo();
        try
        {
            List list = cliParamterDao.queryGuominyaowu(map);
            mo.setList(list);
            mo.setResult(StaticKeys.OH_SUCCESS);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
        }
        return mo;
    }
}
